package com.um.jdy.platform.shop.controller;

import com.um.jdy.platform.shop.entity.dto.GoodsListDTO;
import com.um.jdy.platform.shop.entity.dto.GoodsPageDTO;
import com.um.jdy.platform.shop.entity.dto.GoodsSaveDTO;
import com.um.jdy.platform.shop.entity.vo.GoodsPageVO;
import com.um.springboot.starter.annotation.ApiPermission;
import com.um.springboot.starter.annotation.LoginRequired;
import com.um.jdy.platform.shop.manager.GoodsManager;
import com.um.jdy.common.shop.service.GoodsService;
import com.um.jdy.common.shop.entity.po.Goods;
import com.um.jdy.common.shop.entity.dto.GoodsDTO;
import com.um.jdy.common.shop.entity.vo.GoodsVO;
import com.um.springboot.starter.annotation.TokenRequired;
import com.um.springboot.starter.entity.Page;
import com.um.springboot.starter.orm.controller.BasePlusController;
import com.um.springboot.starter.orm.entity.Response;
import com.um.springboot.starter.orm.params.ListDTO;
import com.um.springboot.starter.orm.params.PageDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

/**
 * 控制器：商品表
 */
@RestController
@RequestMapping("/api/v1/cms/shop/goods")
@Api(tags = "GoodsController", description = "商品表")
@ApiPermission("goods")
@TokenRequired
public class GoodsController extends BasePlusController<GoodsManager, GoodsService, Goods, GoodsDTO, GoodsVO, GoodsPageDTO, GoodsListDTO> {

    @ApiPermission("page")
    @ApiOperation("分页查询商品")
    @PostMapping("get_goods_page")
    public Response<Page<GoodsPageVO>> getGoodsPage(@RequestBody GoodsPageDTO goodsPageDTO) {
        return Response.success(manager.getGoodsPage(goodsPageDTO));
    }

    @ApiPermission("save")
    @ApiOperation("保存商品")
    @PostMapping("save_goods")
    public Response<GoodsVO> saveGoods(@RequestBody GoodsSaveDTO goodsDTO) {
        boolean result = manager.saveGoods(goodsDTO);
        return result ? Response.success() : Response.failed();
    }

    @ApiPermission("status")
    @ApiOperation("修改商品状态")
    @PutMapping("/{id}/status/{status}")
    public Response changeStatus(@PathVariable String id, @PathVariable String status) {
        return manager.changeStatus(id, status);
    }

    @ApiOperation("查询DIY商品")
    @PostMapping("diy_goods_page")
    public Response<Page<GoodsPageVO>> diyGoodsPage(@RequestBody GoodsPageDTO goodsPageDTO) {
        return Response.success(manager.getGoodsPage(goodsPageDTO));
    }
}
